<template>
  <div class="common-container">
    <div class="search-container"><el-button type="primary" size="middle" icon="add" class="addBtn" @click="handleAdd">新增</el-button></div>

    <el-table :data="list" border>
      <el-table-column prop="icon" width="80px" align="center" label="图标">
        <template slot-scope="scope">
          <img class="feature-icon" :src="resBaseUrl + scope.row.icon">
        </template>
      </el-table-column>
      <el-table-column prop="name" align="center" label="插件名称" />
      <el-table-column prop="code" align="center" label="插件编码" />
      <el-table-column prop="description" align="center" label="描述" />
      <el-table-column prop="autoOpen" align="center" label="标签">
        <el-table-column prop="autoOpen1" align="center" label="是否可关闭">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.canClose" type="success">是</el-tag>
            <el-tag v-else>否</el-tag>
          </template>
        </el-table-column>

        <el-table-column align="center" label="操作" width="200px">
          <template slot-scope="scope">
            <el-button size="small" type="primary" class="editBtn" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button v-show="scope.row.code == 'rfm'" size="small" type="primary" class="editBtn" @click="plugConf(scope.row)">插件配置</el-button>
            <!--  <el-button size="small" type="danger" @click="handleDelete(scope.row)">删除</el-button> -->
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>

    <el-pagination
      style="margin-top: 10px "
      :current-page.sync="pageNum"
      :page-size.sync="pageSize"
      layout="total, prev, pager, next"
      :total="total"
      @current-change="handleCurrentChange"
    />

    <PlugMarketDialog ref="featureFormDialog" :scope="scope" :forms="forms" :fetchlist="fetchList" />
    <RfmConfigDialog ref="rfmConfigDialog" />
  </div>
</template>

<script>
import { deleteFeature, queryFeatureList, qryMarketPlugins } from '@/api/feature'
import PlugMarketDialog from './PlugMarketDialog.vue'
import RfmConfigDialog from './RfmConfigDialog.vue'
import { mapGetters } from 'vuex'

export default {
  name: 'Feature',
  components: {
    PlugMarketDialog,
    RfmConfigDialog
  },
  props: {
    scope: {
      require: true,
      type: Number
    }
  },
  computed: {
    ...mapGetters(['resBaseUrl'])
  },
  data() {
    return {
      pageNum: 0,
      pageSize: 10,
      loading: false,
      list: [],
      total: 0,
      forms: {},
      visible: false
    }
  },
  mounted() {
    this.fetchList()
  },
  methods: {
    fetchList() {
      const data = {
        pageSize: this.pageSize,
        pageNum: this.pageNum
      }
      return qryMarketPlugins('0', data).then(res => {
        console.log('基础数据', res)
        if (res.code === 0) {
          this.list = res.data.list
          this.total = res.data.total
        }
        return res
      })
    },
    // 插件配置操作
    plugConf(row) {
      // console.log('插件配置', row)
      this.$refs.rfmConfigDialog.edit()
    },
    // fetchList() {
    //   const data = {
    //     pageSize: this.pageSize,
    //     pageNum: this.pageNum
    //   }
    //   return queryFeatureList(this.scope, data).then(res => {
    //     console.log('基础数据', res)
    //     if (res.code === 0) {
    //       this.list = res.data.list
    //       this.total = res.data.total
    //     }
    //     return res
    //   })
    // },
    // 新增
    handleAdd() {
      this.$refs.featureFormDialog.add().then(() => {
        this.fetchList()
      })
    },
    // 编辑
    handleEdit(feature) {
      console.log('编辑', feature)
      this.forms = feature
      console.log('赋值过后', this.forms)
      // this.$refs.featureFormDialog.edit(feature.id).then(() => {
      //   this.fetchList()
      // })
      setTimeout(() => {
        // 定义一个定时器,歇会之后再跳转
        this.$refs.featureFormDialog.assignmentData()
      }, 100)
    },
    handleCurrentChange() {
      this.fetchList()
    },

    handleDelete(feature) {
      this.$confirm(`此操作将删除插件【${feature.name}】, 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteFeature(this.scope, feature.id).then(res => {
          if (res.code === 0) {
            this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
            this.fetchList()
          }
        })
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.search-container {
	margin-top: 20px;
	margin-bottom: 20px;
	.addBtn,
	.serchBtn,
	.editBtn {
		background-color: $btnBgc;
		border: none;
	}
	.addBtn:hover {
		opacity: 0.5;
	}
	.serchBtn:hover {
		opacity: 0.5;
	}
	::v-deep .el-input__inner:focus {
		border-color: $btnBgc;
	}
}
.editBtn {
	background-color: $btnBgc !important;
	border: none;
	color: $btnFon;
}
.editBtn:hover {
	opacity: 0.5;
}

.search-wrap {
	width: 500px;
	margin-right: 30px;
}
.feature-icon {
	width: 50px;
	height: 50px;
}

.el-pagination.is-background .el-pager li:not(.disabled).active {
	background-color: $btnBgc !important;
	border: none;
	color: $btnFon;
}

::v-deep .el-input--medium .el-input__inner:focus {
	border-color: $btnBgc;
}
::v-deep .el-textarea__inner:focus {
	border-color: $btnBgc;
}
::v-deep .el-checkbox__input.is-checked .el-checkbox__inner {
	border-color: $btnBgc;
	background-color: $btnBgc;
}
::v-deep .el-checkbox__input.is-checked + .el-checkbox__label {
	color: $btnBgc;
}
</style>
